<template>
  <el-dialog
    :title="title"
    :visible.sync="showHide"
    :close-on-click-modal="false"
    v-bind="$attrs"
    :before-close="handleClose"
  >
    <div class="dialog-middle">
      <div class="slot-style" v-show="contentShow">
        <slot />
      </div>
      <div v-show="twoBtn" class="twoBtn">
        <button class="submitBtn1 btnStyle" v-on="$listeners">{{ okBtnText }}</button>
        <button class="submitBtn1 btnStyle" @click="handleClose" v-show="noBtnTextShow">{{ noBtnText }}</button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'KDialog',
  inheritAttrs: false,
  props: {
    okBtnText: {
      type: String,
      default() {
        return '保存'
      }
    },
    noBtnText: {
      type: String,
      default() {
        return '取消'
      }
    },
    // 取消取消按钮
    noBtnTextShow:{
      type: Boolean,
      default:true
    },
    title: { // 标题
      type: String,
      default() {
        return '标题'
      }
    },
    showHide: { // 显示隐藏
      type: Boolean,
      default() {
        return false
      }
    },
    submitFun: { // 提交函数
      type: Function,
      default() {
        return () => {}
      }
    },
    twoBtn: { // 是否展示两个摁钮
      type: Boolean,
      default() {
        return false
      }
    },
    closeFun: {
      type: Function,
      default() {
        return () => {}
      }
    },
    // 是否展示内容
    contentShow:{
      type: Boolean,
      default() {
        return true
      }
    }
  },
  methods: {
    handleClose(type) {
      this.$emit('update:showHide', false)
      this.closeFun(type)
    }
  }
}
</script>

<style lang='scss'>
$mainColor:#3b425d;// 主色调

.el-dialog__wrapper{
    .el-dialog {
    box-shadow: 0px 3px 29px 0px rgba(26, 26, 26, 0.05);
    border-radius: 10px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    -ms-transform: translate(-50%,-50%);
    -webkit-transform: translate(-50%,-50%);
    margin:  auto !important;
    width: auto !important;

}
}
.el-dialog__header{
  box-sizing: border-box;
  position: relative;
  padding: 20px 0px 20px 0px;
  margin: 5px 36px;
  border-bottom: 1px solid #E8E8E8;
  .el-dialog__headerbtn{
    position: absolute;
    right: 0px;
    top: 22px;
    font-weight: bold;
    font-size: 18px;
    .el-dialog__close:hover{
      color: $mainColor;
    }
  }
  .el-dialog__title{
    font-size:18px;
    line-height: 18px;
    font-weight:500;
    color:#4E4F62;
    display: block;
  }
}
.el-dialog__body{
  max-height: 800px;
  overflow: auto;
}

.btnStyle{
  width: 148px;
  height: 44px;
  background: #e7ecf8;
  border: 1px solid #3b425d;
  border-radius: 8px;
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 500;
  color: #3b425d;
}
.btnStyle:hover{
  background: $mainColor;
  color: #fff;
}
.dialog-middle{
  display: flex;
  flex-direction: column;
  justify-content: center;
  .slot-style{
    margin-bottom: 30px;
  }
  .twoBtn{
    // display: flex;
    // flex-direction: row;
    // justify-content: center;
    text-align: center;
    margin-bottom: 30px;
    .submitBtn1{
      display: inline-block;
      cursor: pointer;
    }
    .submitBtn1:nth-of-type(2){
        margin-left: 64px;
    }
  }
}

</style>
